import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'
import FirstPage from '@/views/nav/FirstPage.vue'
import SecondPage from '@/views/nav/SecondPage.vue'
import ThirdPage from '@/views/nav/ThirdPage.vue'
import Dynamic from '@/views/userpages/Dynamic.vue'
import About from '@/views/userpages/About.vue'
import LoginOrReg from '@/components/LoginOrReg'
import GoodsDetailed from '@/views/components/GoodsDetailed'
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: 'first_page',
        name: 'first_page',
        component: FirstPage
      },
      {
        path: 'second_page',
        name: 'second_page',
        component: SecondPage,
        children: [
          {
            path: 'trade_statistic',
            name: 'trade_statistic',
            component: () => import('@/views/components/mystore/TradeStatistic.vue')
          },
          {
            path: 'order_management',
            name: 'order_management',
            component: () => import('@/views/components/mystore/OrderManagement.vue')
          },
          {
            path: 'distribution',
            name: 'distribution',
            component: () => import('@/views/components/mystore/Distribution.vue')
          },
          {
            path: 'information',
            name: 'information',
            component: () => import('@/views/components/mystore/ReleaseInformation.vue')
          },
          {
            path: 'store_goods_list',
            name: 'store_goods_list',
            component: () => import('@/views/components/mystore/StoreGoodsList.vue')
          },
          {
            path: 'release_or_update',
            name: 'release_or_update',
            component: () => import('@/views/components/mystore/ReleaseOrUpdate.vue')
          },
          {
            path : 'my_orders',
            name: 'my_orders',
            component : () => import('@/views/components/mybill/MyOrders.vue')
          },
          {
            path : 'profit_and_loss',
            name: 'profit_and_loss',
            component : () => import('@/views/components/mybill/ProfitAndLoss.vue')
          },
          {
            path : 'funnel',
            name: 'funnel',
            component : () => import('@/views/components/mybill/Funnel.vue')
          }
        ]
      },
      {
        path: 'third_page',
        name: 'third_page',
        component: ThirdPage
      },
      {
        path: 'dynamic',
        name: 'dynamic',
        component: Dynamic
      },
      {
        path: 'about',
        name: 'about',
        component: About
      },
      {
        path: 'goods_detailed/:id',
        name : 'goods_detailed',
        component : GoodsDetailed
      }
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: LoginOrReg
  },
  {
    path: '/test',
    name: 'test',
    component: Dynamic
  },
  {
    path: '/',
    redirect: '/home/first_page'
  }
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})
router.afterEach((to, from, next) => {
  window,
    scrollTo(0, 0)
})
export default router
